<?php
include("config.php");

if(empty($_POST['token'])){
	echo json_res(true,'paramError','提交数据不全!');
	return;
}
//////////////////////////////////////////////////////////////////////////////////////
//获取成绩
$snoopy1 = new Snoopy;
//模拟HEADER
$snoopy1->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
//获取分析表单
$snoopy1->fetch($scoreurl);
$res1 = $snoopy1->results;

//超时返回
if ($snoopy1->status != '200' || $snoopy1->timed_out) {
	echo json_res(true,'systemTimeOut',"页面获取超时！");
	return;
}

if(stripos($res1,"action=\"login.aspx\"")){
	echo json_res(true,'tokenTimeOut',"token失效");
	return;
}

$res1_html = new simple_html_dom();
$res1_html->load($res1);
$res1_tables  = $res1_html->find('table.GridViewStyle');

$info_data    = [];
$info_title   = [];
foreach ($res1_tables as $table_key => $table) {
	$res1_trs     = $table->find('tr');
	foreach ($res1_trs as $key => $value){
		$res1_tds = $value->find('td');
		if($key==0 && count($info_title)==0)
			$info_title = [
				trim(strip_tags($res1_tds[0]->innertext)),
				trim(strip_tags($res1_tds[1]->innertext)),
				trim(strip_tags($res1_tds[2]->innertext)),
				trim(strip_tags($res1_tds[3]->innertext)),
				"课程类型"
			];
		else
			$info_data[] = [
				trim(strip_tags($res1_tds[0]->innertext)),
				trim(strip_tags($res1_tds[1]->innertext)),
				trim(strip_tags($res1_tds[2]->innertext)),
				trim(strip_tags($res1_tds[3]->innertext)),
				$table_key==0?"学位课程":"选修课程"
			];
	}
}
$scoreRow = ["title"=>$info_title,"data"=>$info_data];

$score["title"] = ["课程","学分","学年","学期","学位课","成绩"];
$xn = substr($res1_html->find("#MainWork_lblxh")[0]->innertext,1,2) ;
$xn = "20".$xn."-20".($xn+1);
foreach ($scoreRow["data"] as $key => $value) {
	$score["data"][] = [
		"kc" =>$value[0],
		"xf" =>$value[1],
		"xn" =>$xn,
		"xq" =>$value[2],
		"xwk"=>$value[4]=="学位课程"?"是":"否",
		"cj" =>$value[3]
	];
}
$score["row"] = $scoreRow;

$res1_html->clear();

//////////////////////////////////////////////////////////////////////////////////////
echo json_res(false,$score);
return;

?>